{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'bobby1': {'imooc', 'company'}, 'bobby2': {'imooc', 'company'}, 'bobby': 'imooc'}\n"
     ]
    }
   ],
   "source": [
    "a = {'bobby1': {'company': 'imooc'},\n",
    "    'bobby2': {'company': 'imooc2'}\n",
    "    }\n",
    "\n",
    "## clear\n",
    "# a.clear()\n",
    "################### copy ####################\n",
    "## copy, 返回浅拷贝\n",
    "# new_dict = a.copy()\n",
    "# new_dict['bobby1']['company'] = 'imooc3'\n",
    "\n",
    "## 深拷贝\n",
    "import copy\n",
    "new_dict = copy.deepcopy(a)\n",
    "new_dict['bobby1']['company'] = 'imooc3'\n",
    "# print(a)\n",
    "# print(new_dict)\n",
    "\n",
    "################### fromkeys ####################\n",
    "new_list = ['bobby1', 'bobby2']\n",
    "new_dict = dict.fromkeys(new_list, {'company', 'imooc'})\n",
    "# print(new_dict)\n",
    "\n",
    "################### get ####################\n",
    "# value = new_dict.get('bobby1')\n",
    "# print(value)\n",
    "\n",
    "################### setdefault ####################\n",
    "# default_value = new_dict.setdefault('bobby1', 'imooc')\n",
    "# print(default_value)\n",
    "\n",
    "################### update ####################\n",
    "## 合并\n",
    "# new_dict.update(bobby='imooc', bobby3='imooc3')\n",
    "new_dict.update([(('bobby', 'imooc'))])\n",
    "print(new_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
